$(document).ready(function() {
	//设置datepicker
	$("#meeting_task_start_time").datepicker({
		showAnim: "blind",
		dateFormat: "yy-mm-dd",
		changeYear: true,
		changeMonth: true,
		monthNamesShort: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
		dayNamesMin: ['日', "一", "二", "三", "四", "五", "六"],
		onClose:function(selectedDate){
			$("#meeting_task_end_time").datepicker( "option", "minDate", selectedDate );
		}
	});
	$("#meeting_task_end_time").datepicker({
		showAnim: "blind",
		dateFormat: "yy-mm-dd",
		changeYear: true,
		changeMonth: true,
		monthNamesShort: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
		dayNamesMin: ['日', "一", "二", "三", "四", "五", "六"],
		onClose: function( selectedDate ) {
			$("#meeting_task_start_time").datepicker( "option", "maxDate", selectedDate );
		}
	});
});

function changeDeptTask(obj){
	var deptTaskId=$(obj).val();
	for(var i=0;i<deptTasks.length;i++){
		if(deptTasks[i].deptTaskId==deptTaskId){
			$("#deptTaskPlanStartTime").text(deptTasks[i].deptTaskPlanStartTime.substr(0,10));
			$("#deptTaskPlanEndTime").text(deptTasks[i].deptTaskPlanEndTime.substr(0,10));
			$("#deptTaskPoint").text(deptTasks[i].deptTaskPoint);
		}
	}
}
/**
 * 数据格式验证
 */
function beforeSubmit(){
	var taskName = $('input[name="taskName"]');
	if(taskName.val() == ""){
		$("#check_taskName").text("请输入任务名称！");
		taskName.focus();
		return false;
	}
	var taskDetail = $('#task_detail');
	if(taskDetail.val() == ""){
		$("#check_detail").text("请输入任务详情！");
		taskDetail.focus();
		return false;
	}
	var taskRequirement = $('#task_request');
	if(taskRequirement.val() == ""){
		$("#check_taskRequest").text("请输入任务要求！");
		taskRequirement.focus();
		return false;
	}
	var taskPlanStartTime = $('#meeting_task_start_time');
	if(taskPlanStartTime.val() == ""){
		$("#check_meeting_task_start_time").text("请输入任务开始时间！");
		taskPlanStartTime.focus();
		return false;
	}
	var taskPlanEndTime = $('#meeting_task_end_time');
	if(taskPlanEndTime.val() == ""){
		$("#check_meeting_task_end_time").text("请输入任务结束时间！");
		taskPlanEndTime.focus();
		return false;
	}
	var taskTotalPoint = $('input[name="taskTotalPoint"]');
	
	if(taskTotalPoint.val() == ""){
		$("#check_task_point").text("请输入任务分数！");
		taskTotalPoint.focus();
		return false;
	}else{
		if(!isNaN(taskTotalPoint.val())){
			//console.log($("#deptTaskPoint").text());
			var pp = parseInt($("#deptTaskPoint").text());
			var ps = parseInt(taskTotalPoint.val());
			console.log(pp);
			console.log(ps);
			if(ps > pp){
				$("#check_task_point").text("任务分数大于可以上限，请重新输入分数");
				return false;
		}
		}else{
			$("#check_task_point").text("请输入数字格式的分数！");
			return false;
		}
	}
	
	return true;
}
